package com.ruoyi.system.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.service.IChartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/chart")
public class ChartController extends BaseController {

    @Autowired
    private IChartService chartService;

    @GetMapping("/bar")
    public AjaxResult getBarChartData(@RequestParam(value = "timeRange", defaultValue = "7d") String timeRange) {
        List<Map<String, Object>> data = chartService.getRepairCountByDate(timeRange);
        return AjaxResult.success(data);
    }

    @GetMapping("/pie")
    public AjaxResult getPieChartData() {
        List<Map<String, Object>> data = chartService.getOccupancyStatusCount();
        return AjaxResult.success(data);
    }
}